<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" href="/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>铅山县生态价值评估系统</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>
<script>
    // 限域到可信来源
    const ALLOWED_ORIGINS = ['http://admin.fzskj.com', 'http://localhost:3000', 'http://localhost:5173'];
    window.addEventListener('message', (event) => {
        if (!ALLOWED_ORIGINS.includes(event.origin)) return;

        const data = event.data || {};
        if (data.type === 'SET_TOKEN' && typeof data.token === 'string' && data.token) {
            const key = data.storageKey || 'token';
            try {
                localStorage.setItem(key, data.token);
            } catch (e) {}

            // 可选：同时写 cookie，便于接口层读取
            if (data.cookie && data.cookie.name && data.cookie.value) {
                const maxAge = Number(data.cookie.maxAgeSec) || (7 * 24 * 3600);
                document.cookie = `${data.cookie.name}=${encodeURIComponent(data.cookie.value)}; path=/; max-age=${maxAge}`;
            }
        }
    });

    // 兜底从 URL 读 token
    try {
        const url = new URL(window.location.href);
        const tokenFromQuery = url.searchParams.get('token');
        if (tokenFromQuery) {
            localStorage.setItem('token', tokenFromQuery);
        }
    } catch (e) {}
</script>